package com.hui.dao;



import com.hui.entity.Menu;
import com.hui.mapper.MenuMapper;
import com.hui.util.DruidUtil;

import java.util.List;

/**
 * @Description Menu持久层
 */
public class MenuDao {

    /**
     * 根据id查询菜单数据
     **/
    public List<Menu> findMenuById(int marId) {
        String sql = "SELECT DISTINCT m.*\n" +
                "from tb_mgr_role mr, tb_role_menu tm, tb_menus m\n" +
                "where mr.role_id = tm.role_id and tm.menu_id=m.menu_id\n" +
                "and mr.mgr_id=" + marId;
        return DruidUtil.commonFindListByParam(sql, new MenuMapper());
    }

    /**
     * 根据等级查询菜单数据
     **/
    public List<Menu> findByMenuLevel(int menuLevel) {
        String sql = "select * from tb_menus where menu_level=" + menuLevel;
        return DruidUtil.commonFindListByParam(sql, new MenuMapper());
    }

    /**
     * 根据code查询菜单数据
     **/
    public List<Menu> findByMenuCode(String code) {
        String sql = "select * from tb_menus where parent_menu_code='" + code + "'";
        return DruidUtil.commonFindListByParam(sql, new MenuMapper());
    }

    /**
     * 修改菜单状态
     **/
    public void UpdateByMenuState(int menuId, String menuState) {
        String sql = "update  tb_menus  set menu_state=? where menu_id=?";
        DruidUtil.commonUpdate(sql, menuState, menuId);
    }


    /**
     * 查询所有菜单--用于新增角色是分配权限
     **/
    public List<Menu> findMenuAll() {
        String sql = "SELECT DISTINCT m.*\n" +
                "from tb_mgr_role mr, tb_role_menu tm, tb_menus m\n" +
                "where mr.role_id = tm.role_id and tm.menu_id=m.menu_id";
        return DruidUtil.commonFindListByParam(sql, new MenuMapper());
    }





}
